<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/05/28 21:56:36 $)
// $RCSfile: staff_editpost.php,v $ : $Revision: 1.4 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

if ($_SWIFT["staff"]["t_entab"] == "0")
{
	echo '<font face="Verdana, Arial, Helvetica" size="2" color="red"><b>'.$_SWIFT["language"]["nopermission"].'</b></font>';
	exit;
}

require_once ("./includes/functions_html.php");
$grid = new Grid();
$template->loadLanguageSection("staff_tickets");
$template->loadLanguageSection("staff_editpost");

require_once ("./modules/tickets/functions_ticketsui.php");


/**
* ###############################################
* EDIT TICKET POST
* ###############################################
*/
require_once ("./modules/tickets/functions_ticketmain.php");
$_ticketobj =& new TicketMain($_REQUEST["ticketid"], true);

$_ticketpost = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."ticketposts` WHERE `ticketpostid` = '". intval($_REQUEST["ticketpostid"]) ."';");

if (!$_ticketobj->ticket || empty($_ticketpost["ticketpostid"]) || $_ticketpost["ticketid"] != $_ticketobj->ticket["ticketid"])
{
	echo $_SWIFT["language"]["invalidticket"];
	exit;
}

if ($_POST["step"] == "1" && !empty($_POST["contents"]) && $_SWIFT["staff"]["teditpost"] != "0")
{
	$_ticketobj->updateTicketPost($_POST["ticketpostid"], $_POST["contents"]);

	echo $template->displayTemplate("header.tpl");
	echo '<body onLoad="javascript:reloadOpener();">';
	?>
	<script language="Javascript">
	function reloadOpener()
	{
		if (window.opener)
		{
			window.opener.location.reload(true);
		}
		window.close();
	}
	</script>
	<?
	echo '</body>';

	echo $template->displayTemplate("footer.tpl");
}

if (empty($_POST["step"]))
{
	$template->assign("documenttitle", $_SWIFT["language"]["editpost"]);
	echo $template->displayTemplate("header.tpl");
	echo '<body>';

	printFormStart();
	printMainTableHeader(sprintf($_SWIFT["language"]["editpostt"], $_ticketobj->ticket["ticketmaskid"]), "650");
	$data = array();
	$data[0]["value"] = '<textarea style="WIDTH:100%;" name="contents" cols="100" rows="20">'. htmlspecialchars($_ticketpost["contents"]) .'</textarea>'.SWIFT_CRLF;
	$data[0]["align"] = "center";
	$data[0]["colspan"] = "2";

	printDataRow($data);
	printSubmitRow($_SWIFT["language"]["update"]);

	printMainTableFooter();
	addHiddenField("_m", "tickets");
	addHiddenField("_a", "editticketpost");
	addHiddenField("step", "1");
	addHiddenField("ticketid", intval($_ticketobj->ticket["ticketid"]));
	addHiddenField("ticketpostid", intval($_ticketpost["ticketpostid"]));
	printFormEnd();

	echo '</body>';

	echo $template->displayTemplate("footer.tpl");
}



?>